package cn.bqjr.eily.samples.facade.impl;

import cn.bqjr.eily.samples.entity.po.RoleMenu;
import cn.bqjr.eily.samples.facade.IMenuFacade;
import cn.bqjr.eily.samples.service.base.IMenuService;
import cn.bqjr.eily.samples.service.base.IRoleMenuService;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class MenuFacade implements IMenuFacade {

    private final Logger logger = LoggerFactory.getLogger(MenuFacade.class);

    @Autowired
    private IMenuService menuService;

    @Autowired
    private IRoleMenuService roleMenuService;

    @Override
    public boolean deleteMenu(Long menuId) {
        menuService.deleteById(menuId);
        roleMenuService.delete(new EntityWrapper<RoleMenu>().eq(RoleMenu.MENUID, menuId));
        return true;
    }

    @Override
    public boolean deleteMenuByBatchId(List<Long> menuIds) {
        menuIds.stream().forEach(menuId -> deleteMenu(menuId));
        return true;
    }
}
